package com.feicheng.controller.main.admin.client;


import com.alibaba.fastjson.JSONObject;
import com.feicheng.common.constant.Constant;
import com.feicheng.common.result.ResultInfo;
import com.feicheng.persistence.entity.Vip;
import com.feicheng.persistence.model.VipMain;
import com.feicheng.service.IFClientService;
import com.feicheng.service.IFStoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.Instant;
import java.time.ZoneOffset;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cailongyang
 * @since 2021-12-02
 */
@RestController("/main/admin/client/vip")
@RequestMapping("/main/admin/client/vip")
public class VipController {
    @Autowired
    IFClientService ifClientService;
    @Autowired
    IFStoreService ifStoreService;

    /**
     * 分页查询
     * @param current
     * @param size
     * @param vipMain
     * @return
     */
    @GetMapping("/list")
    public ResultInfo hrs(
            @RequestParam(required = false ,defaultValue = "1") Integer current,
            @RequestParam(required = false ,defaultValue = "10") Integer size,
            VipMain vipMain
    ){
        return ifClientService.getVipsByPage(vipMain, current, size);
    }

    /**
     * 会员详情
     * @param vipId
     * @return
     */
    @GetMapping("/info")
    public ResultInfo getVipById(Integer vipId){
        return ifClientService.getVip(vipId);
    }

    /**
     * 更新会员
     * @param vip
     * @return
     */
    @PutMapping("/info")
    public ResultInfo updateVip(String vip){
        JSONObject param = new JSONObject();
        VipMain vipMain = JSONObject.parseObject(vip,VipMain.class);
        Vip newVip = new Vip();
        newVip.setVipId(vipMain.getVipId());
        newVip.setSt(vipMain.getSt());
        newVip.setEt(vipMain.getEt());
        newVip.setStatu(vipMain.getStatu());
        param.put(Constant.ENTITY.VIP.TABLE,newVip);
        return ifClientService.updateVip(param);
    }

    /**
     * 新增会员
     * @param clientId
     * @param payType
     * @param originalCode
     * @param cardTypeId
     * @param voucher_record_id
     * @param amount
     * @return
     */
    @PostMapping("info")
    public ResultInfo addVip(Integer clientId,String payType,
                             String originalCode,
                             Integer cardTypeId,String voucher_record_id,String amount)
    {
        JSONObject param = new JSONObject();
        param.put(Constant.ENTITY.CLIENT.CLIENT_ID,clientId);
        param.put(Constant.ENTITY.PAYMENT_RECORD.PAY_TYPE,payType);
        param.put(Constant.ENTITY.PAYMENT_RECORD.ORIGINAL_CODE,originalCode);
        param.put(Constant.ENTITY.PAYMENT_RECORD.IO_FLG,1);
        param.put(Constant.ENTITY.VIP.VOUCHER_RECORD_ID,voucher_record_id);
        param.put(Constant.ENTITY.CARD_RECORD.CARD_TYPE_ID,cardTypeId);
        param.put(Constant.ENTITY.CARD_RECORD.AMOUNT,amount);
//      param.put(Constant.ENTITY.VOUCHER_TYPE.VOUCHER_TYPE_ID,voucherTypeId);

        return ifClientService.newVip(param);
    }

}
